import { MonsterHp, MonsterAttack, GameMapItemType } from './../../game/GameDefine';
import GameMapItemWidget from './GameMapItemWidget';

const {ccclass, property, menu} = cc._decorator;

@ccclass
@menu("Widget/Game/GameMapItemMonsterWidget")
export default class GameMapItemMonsterWidget extends GameMapItemWidget {
    @property(cc.Animation)
    anim_monster: cc.Animation = null;
    @property(cc.Node)
    node_image: cc.Node = null;

    @property(cc.Label)
    lb_attack: cc.Label = null;

    protected onLoad(): void {
    }

    public override initWithItem(itemType: GameMapItemType): void {
        super.initWithItem(itemType);

        this.node_image.opacity = 255;
        this.updateProp();
        this.runIdle();
    }

    public runIdle(){
        this.anim_monster.play();
    }

    public runAttack(dir: cc.Vec2){
        return new Promise((resolve, reject)=>{
            cc.tween(this.node_image)
            .by(0.25, {x: dir.x * 50, y: dir.y * 50}, {"easing": "quadOut"})
            .call(resolve)
            .to(0.2, {x: 0, y: 0}, {"easing": "quadIn"})
            .start();
        });
    }

    public runDead(){
        return new Promise((resolve, reject)=>{
            cc.tween(this.node_image)
            .to(0.2, {opacity: 0}, {"easing": "quadOut"})
            .call(resolve)
            .start();
        });
    }

    public updateProp(){
        this.lb_attack.string = MonsterAttack[this._itemType];
    }
}